package com.ifood.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ifood.common.core.domain.entity.FoodOrderMaster;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ifood.common.annotation.Log;
import com.ifood.common.core.controller.BaseController;
import com.ifood.common.core.domain.AjaxResult;
import com.ifood.common.enums.BusinessType;
import com.ifood.system.service.IFoodOrderMasterService;
import com.ifood.common.utils.poi.ExcelUtil;
import com.ifood.common.core.page.TableDataInfo;

/**
 * 订单Controller
 *
 * @author ifood
 * @date 2024-01-14
 */
@RestController
@Api(tags = "订单")
@RequestMapping("/system/master")
public class FoodOrderMasterController extends BaseController {
    @Autowired
    private IFoodOrderMasterService foodOrderMasterService;

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:master:list')")
    @GetMapping("/list")
    @ApiOperation("查询订单列表")
    public TableDataInfo list(FoodOrderMaster foodOrderMaster) {
        startPage();
        List<FoodOrderMaster> list = foodOrderMasterService.selectFoodOrderMasterList(foodOrderMaster);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:master:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FoodOrderMaster foodOrderMaster) {
        List<FoodOrderMaster> list = foodOrderMasterService.selectFoodOrderMasterList(foodOrderMaster);
        ExcelUtil<FoodOrderMaster> util = new ExcelUtil<FoodOrderMaster>(FoodOrderMaster.class);
        util.exportExcel(response, list, "订单数据");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:master:query')")
    @GetMapping(value = "/{orderId}")
    @ApiOperation("获取订单详细信息")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId) {
        return success(foodOrderMasterService.selectFoodOrderMasterByOrderId(orderId));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('system:master:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增订单")
    public AjaxResult add(@RequestBody FoodOrderMaster foodOrderMaster) {
        return toAjax(foodOrderMasterService.insertFoodOrderMaster(foodOrderMaster));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('system:master:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改订单")
    public AjaxResult edit(@RequestBody FoodOrderMaster foodOrderMaster) {
        return toAjax(foodOrderMasterService.updateFoodOrderMaster(foodOrderMaster));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('system:master:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderIds}")
    @ApiOperation("删除订单")
    public AjaxResult remove(@PathVariable String[] orderIds) {
        return toAjax(foodOrderMasterService.deleteFoodOrderMasterByOrderIds(orderIds));
    }
}
